public class Likou_ll1 {
    class Solution {
        public String longestCommonPrefix(String[] strs) {
            if (strs == null || strs.length == 0) {
                return "";
            }
            for (int i = 0; i <strs.length ; i++) {
                if(strs[i].isEmpty()){
                    return "";
                }
            }
            int n = strs[0].length();
            int tem = 0;
            //求最小的字符串的长度
            for (int i = 1; i < strs.length; i++) {
                int a = strs[i].length();
                n=Math.min(n,a);
            }
            for (int i = 0; i <n ; i++) {
                int count = 0;
                char c = strs[0].charAt(i);
                for (int j = 1; j < strs.length ; j++) {
                    if (c == strs[j].charAt(i)) {
                        count++;
                    }
                }
                if(count== strs.length-1){
                    tem++;
                }
                else{
                    break;
                }
            }
            String s = "";
            for (int i = 0; i < tem; i++) {
                s=s+strs[0].charAt(i);
            }
            return s;
        }
    }
}
